/**
 * 
 */

package com.ib.dto;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import com.ib.enumertion.TransactionType;

/**
 * Processing fee details.
 */
public class ProcessingFee implements Serializable, Comparable<ProcessingFee> {

	private static final long serialVersionUID = 1L;
	private String clientId;
	private TransactionType transactionType;
	private Date transactionDate;
	private boolean priority;
	private BigDecimal processingFee;

	/**
	 * @return the clientId
	 */
	public String getClientId() {

		return clientId;
	}

	/**
	 * @param clientId
	 *            the clientId to set
	 */
	public void setClientId(String clientId) {

		this.clientId = clientId;
	}

	/**
	 * @return the transactionType
	 */
	public TransactionType getTransactionType() {

		return transactionType;
	}

	/**
	 * @param transactionType
	 *            the transactionType to set
	 */
	public void setTransactionType(TransactionType transactionType) {

		this.transactionType = transactionType;
	}

	/**
	 * @return the transactionDate
	 */
	public Date getTransactionDate() {

		return transactionDate;
	}

	/**
	 * @param transactionDate
	 *            the transactionDate to set
	 */
	public void setTransactionDate(Date transactionDate) {

		this.transactionDate = transactionDate;
	}

	/**
	 * @return the priority
	 */
	public boolean isPriority() {

		return priority;
	}

	/**
	 * @param priority
	 *            the priority to set
	 */
	public void setPriority(boolean priority) {

		this.priority = priority;
	}

	/**
	 * @return the processingFee
	 */
	public BigDecimal getProcessingFee() {

		return processingFee;
	}

	/**
	 * @param processingFee
	 *            the processingFee to set
	 */
	public void setProcessingFee(BigDecimal processingFee) {

		this.processingFee = processingFee;
	}

	/**
	 * Compare method to be used for sorting Procsssing fee details.
	 */
	@Override
	public int compareTo(ProcessingFee anotherProcessingFee) {

		if (null == anotherProcessingFee) {
			return 0;
		}
		if ( !this.getClientId().equals(anotherProcessingFee.getClientId())) {
			return this.getClientId().compareTo(anotherProcessingFee.getClientId());
		} else if (this.getTransactionType() != anotherProcessingFee.getTransactionType()) {
			return this.getTransactionType().compareTo(anotherProcessingFee.getTransactionType());
		} else if (this.getTransactionDate().compareTo(anotherProcessingFee.getTransactionDate()) != 0) {
			return this.getTransactionDate().compareTo(anotherProcessingFee.getTransactionDate());
		} else if (this.isPriority() != anotherProcessingFee.isPriority()) {
			if (this.isPriority()) {
				return 1;
			} else {
				return -1;
			}
		}
		return 0;
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {

		StringBuilder builder = new StringBuilder();
		builder.append("ProcessingFee [clientId=");
		builder.append(clientId);
		builder.append(", transactionType=");
		builder.append(transactionType);
		builder.append(", transactionDate=");
		builder.append(transactionDate);
		builder.append(", priority=");
		builder.append(priority);
		builder.append(", processingFee=");
		builder.append(processingFee);
		builder.append("]");
		return builder.toString();
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {

		return (13 * this.getClientId().hashCode());
	}

	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {

		if ( !(obj instanceof ProcessingFee) || null == obj) {
			return false;
		}
		ProcessingFee otherObj = (ProcessingFee) obj;
		if (otherObj.getClientId().equals(this.getClientId())
		    && otherObj.getProcessingFee() == this.getProcessingFee()
		    && otherObj.getTransactionType() == this.getTransactionType()
		    && otherObj.getTransactionDate().equals(this.getTransactionDate())) {
			return true;
		}
		return false;
	}
}